function varargout = gui_main(varargin)
% GUI_MAIN MATLAB code for gui_main.fig
%      GUI_MAIN, by itself, creates a new GUI_MAIN or raises the existing
%      singleton*.
%
%      H = GUI_MAIN returns the handle to a new GUI_MAIN or the handle to
%      the existing singleton*.
%
%      GUI_MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUI_MAIN.M with the given input arguments.
%
%      GUI_MAIN('Property','Value',...) creates a new GUI_MAIN or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before gui_main_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to gui_main_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help gui_main

% Last Modified by GUIDE v2.5 06-Dec-2013 01:10:33

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @gui_main_OpeningFcn, ...
                   'gui_OutputFcn',  @gui_main_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
end
% End initialization code - DO NOT EDIT


% --- Executes just before gui_main is made visible.
function gui_main_OpeningFcn(hObject, eventdata, handles, varargin)
    % This function has no output args, see OutputFcn.
    % hObject    handle to figure
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    % varargin   command line arguments to gui_main (see VARARGIN)

    %axes(handles.axes1);
    %handles.input = varargin{1};
    %handles.input2 = handles.input;
    %handles.result = varargin{1};
    %handles.first = handles.input;
    %imshow(handles.input);
    axis off

    % Choose default command line output for gui_main
    handles.output = hObject;

    % Update handles structure
    guidata(hObject, handles);

    % UIWAIT makes gui_main wait for user response (see UIRESUME)
    uiwait(handles.figure1);
end


% --- Outputs from this function are returned to the command line.
function varargout = gui_main_OutputFcn(hObject, eventdata, handles) 
    % varargout  cell array for returning output args (see VARARGOUT);
    % hObject    handle to figure
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)

    % Get default command line output from handles structure
    varargout{1} = handles.result;
    close(handles.figure1);
end

% --- Executes on slider movement.
function brightness_Callback(hObject, eventdata, handles)
    % hObject    handle to brightness (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)

    % Hints: get(hObject,'Value') returns position of slider
    %        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
   % maxi = max(handles.input(:));
    b = get(hObject,'value');
    bild = handles.input2;
    dif = 255*b;
    temp = bild + dif;
    handles.input = temp;
    handles.result = temp;
    axes(handles.axes1);
    imshow(temp);
    guidata(hObject, handles);
end

% --- Executes on slider movement.
function contrast_Callback(hObject, eventdata, handles)
    % hObject    handle to contrast (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)

    % Hints: get(hObject,'Value') returns position of slider
    %        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

    range = [get(hObject, 'Value'), 1];
    bild = handles.input;
    conbild = imadjust(bild, stretchlim(bild,range),[0 1]);
    axes(handles.axes1);
    imshow(conbild);
    handles.input2 = conbild;
    handles.result = conbild;
    guidata(hObject, handles);
end

% --- Executes on button press in nextcanny.
function nextcanny_Callback(hObject, eventdata, handles)
    % hObject    handle to nextcanny (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    %close(handles.figure1);
    uiresume(handles.figure1);
end


% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

handles.input = handles.first;
handles.input2 = handles.first;
handles.result = handles.first;
imshow(handles.first);
set(handles.brightness,'value', 0);
set(handles.contrast, 'value', 0);
guidata(hObject, handles);
end


% --- Executes on button press in load.
function load_Callback(hObject, eventdata, handles)
% hObject    handle to load (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[Filename, Pathname] = uigetfile('*.*', 'Waehlen Sie ein Bild aus');
I = fullfile(Pathname, Filename);
bild = imread(I);
axes(handles.axes1);
imshow(bild);
handles.input = bild;
handles.input2 = handles.input;
handles.result = bild;
handles.first = handles.input;
guidata(hObject, handles);

end
